<html>
  <head>
    <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>S3FS | Elvis Zhang</title>
<meta name="description" content="The easy way or the right way." />
<link rel="shortcut icon" href="https://blog.shunzi.tech/favicon.ico">
<link rel="stylesheet" href="https://blog.shunzi.tech/styles/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css">

<script data-ad-client="ca-pub-7661668224317940" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script src="https://blog.shunzi.tech/media/js/jquery.min.js"></script>
<script src="https://blog.shunzi.tech/media/js/masonry.pkgd.min.js"></script>
<script src="https://blog.shunzi.tech/media/js/aos.js"></script>
<script src="https://blog.shunzi.tech/media/js/pace.min.js"></script>
<script src="https://blog.shunzi.tech/media/js/view-image.min.js"></script>
<script src="https://blog.shunzi.tech/media/js/jquery.magnific-popup.min.js"></script>
<script src="https://blog.shunzi.tech/media/js/functions.js"></script>
    <meta name="referrer" content="never">
    <meta name="description" content="

FUSE-based file system backed by Amazon S3
基于对象存储的文件系统，国内有 aliyun/ossfs, huaweicloud/obsfs
本质是实现了将对象存储的 Bucket 挂载到了本地文..." />
    <meta name="keywords" content="存储,对象存储,云计算" />
    <script src="https://blog.shunzi.tech/media/js/waterfall.min.js"></script>
    <script src="https://blog.shunzi.tech/media/js/prism.min.js"></script>
  </head>
  <body>
            <header id="header" class="grid-container">
        <!-- start: .menu-wrapper -->
        <div class="menu-mobile"> 
          <i class="fa fa-reorder"></i>
        </div>
        <div class="menu-wrapper">
          <div class="">
            <div class="logo">
              <a href="https://blog.shunzi.tech"><img src="\media\images\custom-headerLogo.jpg" alt=""></a>
            </div>
            <!-- start: .main-nav -->

            <nav class="main-nav grid-container grid-parent">
              <ul id="menu-header" class="menu gradient-effect">
                <li class=""><a href="https://blog.shunzi.tech" class="menu">首页</a></li>
                
                  <li class="" >
                    <a href="/archives" class="menu">
                      归档
                    </a>
                  </li>
                
                  <li class="" >
                    <a href="/tag/diary" class="menu">
                      随笔
                    </a>
                  </li>
                
                  <li class="" >
                    <a href="/movies" class="menu">
                      观影
                    </a>
                  </li>
                
                  <li class="" >
                    <a href="/post/about" class="menu">
                      关于
                    </a>
                  </li>
                
                <li class="search-menu-item hide-on-mobile hide-on-tablet"><a href="#search-lightbox" class="lightbox mfp-inline"><i class="fa fa-search-line"></i></a></li>
              </ul>
            </nav>
            <a href="#search-lightbox" class="lightbox epcl-search-button mfp-inline hide-on-tablet hide-on-desktop"><i class="fa fa-search-line"></i></a>
            <!-- end: .main-nav -->
            <div class="clear"></div>
            <div class="border hide-on-tablet hide-on-mobile"></div>
          </div>    
          <div class="clear"></div>
        </div>
        <!-- end: .menu-wrapper -->
        <div class="clear"></div>
      </header>
      <div class="hide-on-mobile hide-on-tablet hide-on-desktop">
        <div id="search-lightbox" class="grid-container grid-small grid-parent mfp-hide">
          <div class="search-wrapper section">
            <form id="gridea-search-form" data-update="1620954331293" action="/search/index.html" class="search-form" _lpchecked="1">
              <input type="text" name="q" id="s" value="" class="search-field" placeholder="搜点啥..." aria-label="搜点啥..." required="">
              <button type="submit" class="submit" aria-label="Submit">
                <i class="fa fa-search-line"></i>
              </button>
            </form>
          </div>
        </div>
      </div>

      <main id="single" class="main grid-container fullcover no-sidebar aos-init aos-animate" data-aos="fade">

        <div class="center content">
          <div class="featured-image cover" style="background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200522175313.png');">
            <div class="meta top"> 
              <time class="meta-info" style="float:left;" datetime="2020-05-22"><i class="fa fa-calendar"></i><span class="lately">1 年前</span></time>
              
              <a href="https://blog.shunzi.tech/post/s3fs/#comments" class="comments meta-info" title="">
                <i class="fa fa-comment remixicon"></i><span class="comment-count valine-comment-count" data-xid="/s3fs/"> </span>
              </a>
              <span id="/s3fs/" class="leancloud_visitors views-counter meta-info" title=""><i class="fa fa-leancloud remixicon"></i><span class="leancloud-visitors-count"></span></span>
              
            </div>
            <div class="info">
              <div class="tags ">
                
                      <a href="https://blog.shunzi.tech/tag/3zCwFWPHxH/" class="ctag ctag-0 ctag-3zCwFWPHxH" aria-label="">存储</a>
                    
                      <a href="https://blog.shunzi.tech/tag/ZnIN9Ge-w/" class="ctag ctag-1 ctag-ZnIN9Ge-w" aria-label="">对象存储</a>
                    
                      <a href="https://blog.shunzi.tech/tag/4zx4ysLGro/" class="ctag ctag-2 ctag-4zx4ysLGro" aria-label="">云计算</a>
                    
              </div>
              <h1 class="title ularge white bold">S3FS</h1>
            </div>
          </div>
        </div>  

        <div class="epcl-page-wrapper">
          <div class="left-content grid-70 np-mobile">
            <article class="main-article post">
              <section class="post-content">
                <div class="text">
                  <blockquote>
<ul>
<li>FUSE-based file system backed by Amazon S3</li>
<li>基于对象存储的文件系统，国内有 aliyun/ossfs, huaweicloud/obsfs</li>
<li>本质是实现了将对象存储的 Bucket 挂载到了本地文件系统中，从而通过本地文件系统操作 OSS 上的对象</li>
</ul>
</blockquote>
<!-- more -->
<h1 id="s3fs">S3FS</h1>
<ul>
<li><a href="https://github.com/s3fs-fuse/s3fs-fuse">S3FS Github Repo</a></li>
<li><a href="https://manpages.ubuntu.com/manpages/xenial/man1/s3fs.1.html">Ubuntu Man Page S3FS</a></li>
</ul>
<h2 id="overfiew">Overfiew</h2>
<ul>
<li>S3FS 是一个 FUSE 文件系统，它允许您将 Amazon S3 bucket 挂载为本地文件系统。它在 S3 中以自然和透明的方式存储文件。您可以使用其他程序来访问相同的文件)。s3fs 可以处理的对象的最大大小取决于 Amazon S3。例如，当使用单一 PUT API 时，可以达到 5GB。当使用多部分上传 API 时，最多支持 5TB。</li>
<li>s3fs 是稳定的，并在许多生产环境中使用，例如，<a href="https://blog.csdn.net/qq_32706349/article/details/91451053">rsync</a> 备份到 s3。</li>
</ul>
<h2 id="dependency">Dependency</h2>
<h3 id="fuse">FUSE</h3>
<ul>
<li>FUSE: File System In User Space. 用户态文件系统，实现逻辑可以在用户态层面代码高度定制，相比于传统的内核文件系统如 Ext4 等，易用性更高，效率因为用户态和内核态的频繁切换相对较低。</li>
<li>内核必须支持 FUSE, 2.6.18-164 之前的内核可能不支持 FUSE。虚拟专用服务器(VPS)可能没有在其内核中编译 FUSE 支持。</li>
<li><a href="https://my.oschina.net/fileoptions/blog/2996339">黑客画家：什么是 FUSE？</a></li>
</ul>
<h3 id="s3-standard-object-storage">S3 Standard Object Storage</h3>
<ul>
<li>由于是基于对象存储构建的存储系统，所以需要一个对象存储系统，S3FS 则是针对实现了 S3 标准的对象存储构建的本地文件系统。</li>
</ul>
<h2 id="features">Features</h2>
<ul>
<li>支持POSIX 文件系统的大部分功能，包括文件读写，目录，链接操作，权限， uid/gid，以及扩展属性（extended attributes）</li>
<li>支持随机写和追加写</li>
<li>大文件使用分片上传</li>
<li>通过在服务端拷贝实现 rename</li>
<li>MD5 数据完整性校验</li>
<li>内存缓存元数据</li>
<li>本地磁盘数据缓存</li>
<li>...</li>
</ul>
<h2 id="limitations">Limitations</h2>
<p>不能完全等价于内核态的文件系统，无论是性能还是语义支持方面都存在一定差距。</p>
<ul>
<li>随机写和追加写可能导致整个文件的重写，可以使用分片上传进行优化</li>
<li>元数据的相关操作，例如枚举，性能较差，因为要访问对象存储</li>
<li>底层对象存储系统的最终一致性可能会使得 S3FS 暂时产生一些过时的数据</li>
<li>文件/文件夹的rename操作不是原子的。</li>
<li>多客户端挂载同一个 Bucket 时需要协调各个客户端的行为，避免对一个文件的不同客户端的并发写</li>
<li>不支持 hard link</li>
<li>不适合用在高并发读/写的场景，这样会让系统的 load 升高</li>
</ul>
<h2 id="原理">原理</h2>
<h3 id="机制">机制</h3>
<h4 id="1读取文件">1.读取文件</h4>
<ul>
<li>
<p>S3FS 对于文件的存储分为临时文件和缓存两种方式，用户可以在命令行中通过 use_cache 参数指定缓存目录来启动缓存方式。</p>
</li>
<li>
<p>用户通过 offset 和 size 来读取指定文件中的特定区域，如果本地没有相应的内容 S3FS 会通过网络请求 S3 上的相应内容，并且将对应的内容存储到本地的临时文件或者缓存中。</p>
</li>
</ul>
<h4 id="2文件逻辑架构">2.文件逻辑架构</h4>
<ul>
<li>不管是临时文件还是缓存文件，S3FS 都用同一个逻辑架构组织这个文件，S3FS 使用一个页的列表来代表一个文件，每页都是这个文件中的一部分：<br>
<img src="https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200522113024.png" alt="20200522113024" loading="lazy"></li>
</ul>
<h5 id="组成"><strong>组成</strong>：</h5>
<ul>
<li>FDPage: 代表了一个文件中的一页，即也是文件中的部分内容。</li>
</ul>
<pre><code class="language-C++">//------------------------------------------------
// fdpage &amp; PageList
//------------------------------------------------
// page block information
struct fdpage
{
  off_t  offset;    // 偏移量
  off_t  bytes;     // 页的大小 
  bool   loaded;    // 是否加载到了本地
  bool   modified;  // 是否修改

  // 构造函数
  fdpage(off_t start = 0, off_t  size = 0, bool is_loaded = false, bool is_modified = false)
           : offset(start), bytes(size), loaded(is_loaded), modified(is_modified) {}

  // 获取下一页对应的偏移量
  off_t next(void) const { return (offset + bytes); }
  // 获取该页的末尾对应的偏移量
  off_t end(void) const { return (0 &lt; bytes ? offset + bytes - 1 : 0); }
};
// Page List
typedef std::list&lt;struct fdpage&gt; fdpage_list_t;
</code></pre>
<ul>
<li>PageList：代表一个本地文件，它是 FDPage 的一个链表。</li>
</ul>
<pre><code class="language-C++">class PageList
{
  friend class FdEntity;    // only one method access directly pages.

  private:
    fdpage_list_t pages;

  public:
    // 页状态枚举
    enum page_status{
      PAGE_NOT_LOAD_MODIFIED = 0,
      PAGE_LOADED,
      PAGE_MODIFIED,
      PAGE_LOAD_MODIFIED
    };

  private:
    void Clear(void);
    bool Compress(bool force_modified = false);
    bool Parse(off_t new_pos);
    bool RawGetUnloadPageList(fdpage_list_t&amp; dlpages, off_t offset, off_t size);

  public:
    static void FreeList(fdpage_list_t&amp; list);

    explicit PageList(off_t size = 0, bool is_loaded = false, bool is_modified = false);
    explicit PageList(const PageList&amp; other);
    ~PageList();

    bool Init(off_t size, bool is_loaded, bool is_modified);
    off_t Size(void) const;
    bool Resize(off_t size, bool is_loaded, bool is_modified);

    bool IsPageLoaded(off_t start = 0, off_t size = 0) const;                  // size=0 is checking to end of list
    bool SetPageLoadedStatus(off_t start, off_t size, PageList::page_status pstatus = PAGE_LOADED, bool is_compress = true);
    bool FindUnloadedPage(off_t start, off_t&amp; resstart, off_t&amp; ressize) const;
    off_t GetTotalUnloadedPageSize(off_t start = 0, off_t size = 0) const;    // size=0 is checking to end of list
    int GetUnloadedPages(fdpage_list_t&amp; unloaded_list, off_t start = 0, off_t size = 0) const;  // size=0 is checking to end of list
    bool GetLoadPageListForMultipartUpload(fdpage_list_t&amp; dlpages);
    bool GetMultipartSizeList(fdpage_list_t&amp; mplist, off_t partsize) const;

    bool IsModified(void) const;
    bool ClearAllModified(void);

    bool Serialize(CacheFileStat&amp; file, bool is_output, ino_t inode);
    void Dump(void);
};
</code></pre>
<ul>
<li>FdEntity：对一个文件的全面描述，包括页链表、本地文件描述符、文件路径等。</li>
</ul>
<pre><code class="language-C++">class FdEntity
{
  private:
    static bool     mixmultipart;   // whether multipart uploading can use copy api.

    pthread_mutex_t fdent_lock;
    bool            is_lock_init;
    int             refcnt;         // reference count 用于刷回
    std::string     path;           // object path
    int             fd;             // file descriptor(tmp file or cache file)
    FILE*           pfile;          // file pointer(tmp file or cache file)
    ino_t           inode;          // inode number for cache file
    headers_t       orgmeta;        // original headers at opening
    off_t           size_orgmeta;   // original file size in original headers

    pthread_mutex_t fdent_data_lock;// protects the following members
    PageList        pagelist;
    std::string     upload_id;      // for no cached multipart uploading when no disk space
    etaglist_t      etaglist;       // for no cached multipart uploading when no disk space
    off_t           mp_start;       // start position for no cached multipart(write method only)
    off_t           mp_size;        // size for no cached multipart(write method only)
    std::string     cachepath;      // local cache file path
                                    // (if this is empty, does not load/save pagelist.)
    std::string     mirrorpath;     // mirror file path to local cache file path

  private:
    static int FillFile(int fd, unsigned char byte, off_t size, off_t start);
    static ino_t GetInode(int fd);

    void Clear(void);
    ino_t GetInode(void);
    int OpenMirrorFile(void);
    bool SetAllStatus(bool is_loaded);                          // [NOTE] not locking
    //bool SetAllStatusLoaded(void) { return SetAllStatus(true); }
    bool SetAllStatusUnloaded(void) { return SetAllStatus(false); }

  public:
    static bool SetNoMixMultipart(void);

    explicit FdEntity(const char* tpath = NULL, const char* cpath = NULL);
    ~FdEntity();

    void Close(void);
    bool IsOpen(void) const { return (-1 != fd); }
    int Open(headers_t* pmeta = NULL, off_t size = -1, time_t time = -1, bool no_fd_lock_wait = false);
    bool OpenAndLoadAll(headers_t* pmeta = NULL, off_t* size = NULL, bool force_load = false);
    int Dup(bool lock_already_held = false);

    const char* GetPath(void) const { return path.c_str(); }
    bool RenamePath(const std::string&amp; newpath, std::string&amp; fentmapkey);
    int GetFd(void) const { return fd; }
    bool IsModified(void) const { return pagelist.IsModified(); }

    bool GetStats(struct stat&amp; st, bool lock_already_held = false);
    int SetCtime(time_t time);
    int SetMtime(time_t time, bool lock_already_held = false);
    bool UpdateCtime(void);
    bool UpdateMtime(void);
    bool GetSize(off_t&amp; size);
    bool SetMode(mode_t mode);
    bool SetUId(uid_t uid);
    bool SetGId(gid_t gid);
    bool SetContentType(const char* path);

    int Load(off_t start = 0, off_t size = 0, bool lock_already_held = false, bool is_modified_flag = false);  // size=0 means loading to end
    int NoCacheLoadAndPost(off_t start = 0, off_t size = 0);   // size=0 means loading to end
    int NoCachePreMultipartPost(void);
    int NoCacheMultipartPost(int tgfd, off_t start, off_t size);
    int NoCacheCompleteMultipartPost(void);

    int RowFlush(const char* tpath, bool force_sync = false);
    int Flush(bool force_sync = false) { return RowFlush(NULL, force_sync); }

    ssize_t Read(char* bytes, off_t start, size_t size, bool force_load = false);
    ssize_t Write(const char* bytes, off_t start, size_t size);

    bool ReserveDiskSpace(off_t size);
};
typedef std::map&lt;std::string, class FdEntity*&gt; fdent_map_t;   // key=path, value=FdEntity*
</code></pre>
<h3 id="io-流程">IO 流程</h3>
<h4 id="读取文件流程">读取文件流程</h4>
<figure data-type="image" tabindex="1"><img src="https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200522171537.png" alt="20200522171537" loading="lazy"></figure>
<ul>
<li>不启用缓存模式：不启用缓存模式下，S3FS 会在本地新建一个临时文件来存储网络传送过来的数据，读取结束后关闭相应的句柄，这样做得好处是如果多个进程同时读取同一个文件就不需要频繁的发起网络请求，当这个临时文件的所有句柄都关闭后这个临时文件也会删除。</li>
</ul>
<pre><code class="language-C++">if(0 == refcnt){
      AutoLock auto_data_lock(&amp;fdent_data_lock);
      if(!cachepath.empty()){
        // [NOTE]
        // Compare the inode of the existing cache file with the inode of
        // the cache file output by this object, and if they are the same,
        // serialize the pagelist.
        //
        ino_t cur_inode = GetInode();
        if(0 != cur_inode &amp;&amp; cur_inode == inode){
          CacheFileStat cfstat(path.c_str());
          if(!pagelist.Serialize(cfstat, true, inode)){
            S3FS_PRN_WARN(&quot;failed to save cache stat file(%s).&quot;, path.c_str());
          }
        }
      }
      if(pfile){
        fclose(pfile);
        pfile = NULL;
      }
      fd    = -1;
      inode = 0;

      if(!mirrorpath.empty()){
        if(-1 == unlink(mirrorpath.c_str())){
          S3FS_PRN_WARN(&quot;failed to remove mirror cache file(%s) by errno(%d).&quot;, mirrorpath.c_str(), errno);
        }
        mirrorpath.erase();
      }
</code></pre>
<ul>
<li>启用缓存模式：启用缓存模式下，S3FS 会将 S3 的数据在本地缓存一份，如果磁盘空间不够，S3FS 会删除部分没有连接的文件来预留出磁盘空间。对于需要经常访问的文件，有一份在本地的缓存非常有必要。</li>
</ul>
<h5 id="read-op">Read OP</h5>
<pre><code class="language-C++">ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load)
{
  S3FS_PRN_DBG(&quot;[path=%s][fd=%d][offset=%lld][size=%zu]&quot;, path.c_str(), fd, static_cast&lt;long long int&gt;(start), size);

  if(-1 == fd){
    return -EBADF;
  }
  AutoLock auto_lock(&amp;fdent_data_lock);

  if(force_load){
    pagelist.SetPageLoadedStatus(start, size, PageList::PAGE_NOT_LOAD_MODIFIED);
  }

  ssize_t rsize;

  // check disk space
  if(0 &lt; pagelist.GetTotalUnloadedPageSize(start, size)){
    // load size(for prefetch)
    size_t load_size = size;
    if(start + static_cast&lt;ssize_t&gt;(size) &lt; pagelist.Size()){
      ssize_t prefetch_max_size = max(static_cast&lt;off_t&gt;(size), S3fsCurl::GetMultipartSize() * S3fsCurl::GetMaxParallelCount());

      if(start + prefetch_max_size &lt; pagelist.Size()){
        load_size = prefetch_max_size;
      }else{
        load_size = pagelist.Size() - start;
      }
    }

    if(!ReserveDiskSpace(load_size)){
      S3FS_PRN_WARN(&quot;could not reserve disk space for pre-fetch download&quot;);
      load_size = size;
      if(!ReserveDiskSpace(load_size)){
        S3FS_PRN_ERR(&quot;could not reserve disk space for pre-fetch download&quot;);
        return -ENOSPC;
      }
    }

    // Loading
    int result = 0;
    if(0 &lt; size){
      result = Load(start, load_size, /*lock_already_held=*/ true);
    }

    FdManager::FreeReservedDiskSpace(load_size);

    if(0 != result){
      S3FS_PRN_ERR(&quot;could not download. start(%lld), size(%zu), errno(%d)&quot;, static_cast&lt;long long int&gt;(start), size, result);
      return -EIO;
    }
  }
  // Reading
  if(-1 == (rsize = pread(fd, bytes, size, start))){
    S3FS_PRN_ERR(&quot;pread failed. errno(%d)&quot;, errno);
    return -errno;
  }
  return rsize;
}
</code></pre>
<h5 id="write-op">Write OP</h5>
<pre><code class="language-C++">ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size)
{
  S3FS_PRN_DBG(&quot;[path=%s][fd=%d][offset=%lld][size=%zu]&quot;, path.c_str(), fd, static_cast&lt;long long int&gt;(start), size);

  if(-1 == fd){
    return -EBADF;
  }
  // check if not enough disk space left BEFORE locking fd
  if(FdManager::IsCacheDir() &amp;&amp; !FdManager::IsSafeDiskSpace(NULL, size)){
    FdManager::get()-&gt;CleanupCacheDir();
  }
  AutoLock auto_lock(&amp;fdent_data_lock);

  // check file size
  if(pagelist.Size() &lt; start){
    // grow file size
    if(-1 == ftruncate(fd, start)){
      S3FS_PRN_ERR(&quot;failed to truncate temporary file(%d).&quot;, fd);
      return -EIO;
    }
    // add new area
    pagelist.SetPageLoadedStatus(pagelist.Size(), start - pagelist.Size(), PageList::PAGE_MODIFIED);
  }

  int     result = 0;
  ssize_t wsize;

  if(0 == upload_id.length()){
    // check disk space
    off_t restsize = pagelist.GetTotalUnloadedPageSize(0, start) + size;
    if(ReserveDiskSpace(restsize)){
      // enough disk space

      // Load uninitialized area which starts from 0 to (start + size) before writing.
      if(!FdEntity::mixmultipart){
        if(0 &lt; start){
          result = Load(0, start, /*lock_already_held=*/ true);
        }
      }

      FdManager::FreeReservedDiskSpace(restsize);
      if(0 != result){
        S3FS_PRN_ERR(&quot;failed to load uninitialized area before writing(errno=%d)&quot;, result);
        return static_cast&lt;ssize_t&gt;(result);
      }
    }else{
      // no enough disk space
      if(0 != (result = NoCachePreMultipartPost())){
        S3FS_PRN_ERR(&quot;failed to switch multipart uploading with no cache(errno=%d)&quot;, result);
        return static_cast&lt;ssize_t&gt;(result);
      }
      // start multipart uploading
      if(0 != (result = NoCacheLoadAndPost(0, start))){
        S3FS_PRN_ERR(&quot;failed to load uninitialized area and multipart uploading it(errno=%d)&quot;, result);
        return static_cast&lt;ssize_t&gt;(result);
      }
      mp_start = start;
      mp_size  = 0;
    }
  }else{
    // already start multipart uploading
  }

  // Writing
  if(-1 == (wsize = pwrite(fd, bytes, size, start))){
    S3FS_PRN_ERR(&quot;pwrite failed. errno(%d)&quot;, errno);
    return -errno;
  }
  if(0 &lt; wsize){
    pagelist.SetPageLoadedStatus(start, wsize, PageList::PAGE_LOAD_MODIFIED);
  }

  // Load uninitialized area which starts from (start + size) to EOF after writing.
  if(!FdEntity::mixmultipart){
    if(pagelist.Size() &gt; start + static_cast&lt;off_t&gt;(size)){
      result = Load(start + size, pagelist.Size(), /*lock_already_held=*/ true);
      if(0 != result){
        S3FS_PRN_ERR(&quot;failed to load uninitialized area after writing(errno=%d)&quot;, result);
        return static_cast&lt;ssize_t&gt;(result);
      }
    }
  }

  // check multipart uploading
  if(0 &lt; upload_id.length()){
    mp_size += wsize;
    if(S3fsCurl::GetMultipartSize() &lt;= mp_size){
      // over one multipart size
      if(0 != (result = NoCacheMultipartPost(fd, mp_start, mp_size))){
        S3FS_PRN_ERR(&quot;failed to multipart post(start=%lld, size=%lld) for file(%d).&quot;, static_cast&lt;long long int&gt;(mp_start), static_cast&lt;long long int&gt;(mp_size), fd);
        return result;
      }
      // [NOTE]
      // truncate file to zero and set length to part offset + size
      // after this, file length is (offset + size), but file does not use any disk space.
      //
      if(-1 == ftruncate(fd, 0) || -1 == ftruncate(fd, (mp_start + mp_size))){
        S3FS_PRN_ERR(&quot;failed to truncate file(%d).&quot;, fd);
        return -EIO;
      }
      mp_start += mp_size;
      mp_size   = 0;
    }
  }
  return wsize;
}
</code></pre>
<h4 id="读取文件网络请求流程">读取文件网络请求流程</h4>
<ul>
<li>通过网络请求 S3 的数据，S3FS 分为了两种，一种是单次请求，一种是多次请求，请求流程如下：<br>
<img src="https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200522171651.png" alt="20200522171651" loading="lazy"></li>
<li>单次请求：默认情况下单次请求的大小在 20M 以下，S3FS 会通过单个请求完成数据的请求。</li>
<li>多次请求：默认情况下如果请求的数据在 20M 以上，S3FS 会切割数据进行多次请求，每次请求 10M 的数据，对单个文件的请求每次最多启动 5 个线程来进行数据的获取，并且是在 5 个线程都请求完成后才会启动下一轮请求。</li>
</ul>
<h5 id="请求-s3">请求 S3</h5>
<pre><code class="language-C++">int FdEntity::Load(off_t start, off_t size, bool lock_already_held, bool is_modified_flag)
{
  AutoLock auto_lock(&amp;fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);

  S3FS_PRN_DBG(&quot;[path=%s][fd=%d][offset=%lld][size=%lld]&quot;, path.c_str(), fd, static_cast&lt;long long int&gt;(start), static_cast&lt;long long int&gt;(size));

  if(-1 == fd){
    return -EBADF;
  }
  AutoLock auto_data_lock(&amp;fdent_data_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);

  int result = 0;

  // check loaded area &amp; load
  fdpage_list_t unloaded_list;
  if(0 &lt; pagelist.GetUnloadedPages(unloaded_list, start, size)){
    for(fdpage_list_t::iterator iter = unloaded_list.begin(); iter != unloaded_list.end(); ++iter){
      if(0 != size &amp;&amp; start + size &lt;= iter-&gt;offset){
        // reached end
        break;
      }
      // check loading size
      off_t need_load_size = 0;
      if(iter-&gt;offset &lt; size_orgmeta){
        // original file size(on S3) is smaller than request.
        need_load_size = (iter-&gt;next() &lt;= size_orgmeta ? iter-&gt;bytes : (size_orgmeta - iter-&gt;offset));
      }

      // download
      if(S3fsCurl::GetMultipartSize() &lt;= need_load_size &amp;&amp; !nomultipart){
        // parallel request
        result = S3fsCurl::ParallelGetObjectRequest(path.c_str(), fd, iter-&gt;offset, need_load_size);
      }else{
        // single request
        if(0 &lt; need_load_size){
          S3fsCurl s3fscurl;
          result = s3fscurl.GetObjectRequest(path.c_str(), fd, iter-&gt;offset, need_load_size);
        }else{
          result = 0;
        }
      }
      if(0 != result){
        break;
      }
      // Set loaded flag
      pagelist.SetPageLoadedStatus(iter-&gt;offset, iter-&gt;bytes, (is_modified_flag ? PageList::PAGE_LOAD_MODIFIED : PageList::PAGE_LOADED));
    }
    PageList::FreeList(unloaded_list);
  }
  return result;
}
</code></pre>
<h3 id="源码">源码</h3>
<h4 id="原理概述">原理概述：</h4>
<ul>
<li>代码层面 s3fs 的实现方法主要是：利用 fuse 库实现一个文件系统并挂载到本地文件系统的某个目录下，该文件系统的底层并不使用磁盘存储，而是使用 s3 os 存储(因为文件系统是自己实现的，用什么存储，怎么存储可以自己定)；</li>
</ul>
<h4 id="代码结构">代码结构</h4>
<ul>
<li>s3fs 项目一共有 11 个头文件，除去一个测试代码文件，一共有10个文件系统实现相关的文件，分别是：
<ul>
<li>curl.h：用于请求s3 os中的文件，多线程</li>
<li>fdcache.h：缓存文件相关类，包括fdpage、pagelist、FdEntity、FdManager，主要用于os中文件分页缓存到本地以及缓存文件的相关管理(比如检查存在、创建、清除等) 注意，若文件句柄持有线程为0，则该文件缓存被清除；</li>
<li>psemaphore.h：信号量机制实现类</li>
<li>s3fs.h：s3文件系统实现类，用于利用s3 os 为存储介质，构造一个文件系统挂载到本地文件系统目录中</li>
<li>s3fs_util.h：一些工具类</li>
<li>s3fs_auth.h：用于s3 os的认证</li>
<li>string_util.h：用于处理http协议的(header,body)</li>
<li>cache.h：文件缓存，将已读取或加载的文件缓存到本地，以备以后使用(相当于cpu的三级缓存)</li>
<li>common.h：主要用于日志记录</li>
<li>add_head.h</li>
</ul>
</li>
</ul>
<h2 id="同类产品">同类产品</h2>
<h3 id="ossfs-alicloud">ossfs AliCloud</h3>
<ul>
<li><a href="https://help.aliyun.com/document_detail/32196.html?spm=a2c4g.11174283.6.756.50c77da25kXUri">官方介绍</a></li>
<li><a href="https://github.com/aliyun/ossfs">Github Repo</a></li>
<li>ossfs 能让您在Linux系统中，将对象存储OSS的存储空间（Bucket）挂载到本地文件系统中，您能够像操作本地文件一样操作OSS的对象（Object），实现数据的共享。</li>
</ul>
<h3 id="obsfs-huaweicloud">obsfs HuaweiCloud</h3>
<ul>
<li><a href="https://support.huaweicloud.com/fstg-obs/obs_12_0001.html">官方介绍</a></li>
<li><a href="https://github.com/huaweicloud/huaweicloud-obs-obsfs">Github Repo</a></li>
<li>Obsfs 是基于开源 s3fs 修改的。Obsfs 继承了 s3fs 的一些功能，并为华为云OBS服务开发了一些独特的功能。obsfs 允许 Linux 和 Mac OS X 通过 FUSE 挂载 S3 bucket。</li>
</ul>
<h3 id="references">References</h3>
<ul>
<li><a href="https://github.com/kahing/goofys">goofys</a> - similar to s3fs but has better performance and less POSIX compatibility. <strong>Performance First, POSIX Second</strong>
<ul>
<li>We can try to implement self-define backend object storage service. But we must use Go-Language to call functions given by our object operations sdk.</li>
</ul>
</li>
<li>s3acker - mount an S3 bucket as a single file</li>
<li>S3Proxy - combine with s3fs to mount Backblaze B2, EMC Atmos, Microsoft Azure, and OpenStack Swift buckets.
<ul>
<li>It is used as a S3 Proxy for other object storage service and implements S3 API.</li>
</ul>
</li>
<li>s3ql - similar to s3fs but uses its own object format</li>
<li>YAS3FS - similar to s3fs but uses SNS to allow multiple clients to mount a bucket</li>
</ul>
<h2 id="参考链接">参考链接</h2>
<ul>
<li><a href="https://aws.amazon.com/cn/blogs/china/s3fs-amazon-ec2-linux/">[1] AWS: 利用 S3fs 在Amazon EC2 Linux 实例上挂载 S3 存储桶</a></li>
<li><a href="https://blog.csdn.net/THMAIL/article/details/103567262">[2] CSDN: s3fs 实现原理剖析</a></li>
<li><a href="https://blog.didiyun.com/index.php/2019/01/02/s3fs/">[3] 滴滴云：基于滴滴云搭建 S3FS 及其实现机制剖析</a></li>
</ul>

                </div>
                <div class="clear"></div>
              </section>
            </article>
            <div class="clear"></div>

            <section class="related section">
              
              <article class="prev grid-50 tablet-grid-50 grid-parent">
                <div class="thumb cover lazy loaded" style="background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200611220832.png');"></div>
                 <a href="https://blog.shunzi.tech/post/head-first-go-lang/" class="full-link"></a>
                 <div class="info">
                  <time datetime="2020-06-11">2020-06-11</time>
                  <h4 class="title white no-margin">Head First Golang</h4>
                </div>
                 <span class="epcl-button red">
                  <img src="https://blog.shunzi.tech/media/images/left-arrow.svg" width="15" alt="Left Arrow">
                </span>
                <div class="overlay"></div>
              </article>
              
              
              <article class="next grid-50 tablet-grid-50 grid-parent">
                <div class="thumb cover lazy loaded" style="background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/BigTable_database_large.jpg');"></div>
                 <a href="https://blog.shunzi.tech/post/BigTable-A-Distributed-Storage-System-for-Structured-Data/" class="full-link"></a>
                 <div class="info">
                  <time datetime="2020-05-19">2020-05-19</time>
                  <h4 class="title white no-margin">Bigtable: A Distributed Storage System for Structured Data</h4>
                </div>
                 <span class="epcl-button red">
                  <img src="https://blog.shunzi.tech/media/images/right-arrow.svg" width="15" alt="Left Arrow">
                </span>
                <div class="overlay"></div>
              </article>
              

                <div class="clear"></div>
            </section>

              <div class="clear"></div>
              
            
              <div id="comments" class="bg-white hosted ">
                <div class="clear"></div>
<script>
jQuery(document).ready(function($){
    $('.vemoji-btn').text('😀');
    $("#comments").on('click', 'span.vat',function(){
        $(this).parent('div.vmeta').next("div.vcontent").after($("div.vwrap"));
        $('textarea#veditor').focus();
    })
    if(window.location.hash){
        var checkExist = setInterval(function() {
            if ($(window.location.hash).length) {
                $('html, body').animate({scrollTop: $(window.location.hash).offset().top-200}, 600);
                clearInterval(checkExist);
            }
        }, 100);
    }
})
</script>

              </div>
            

            </div>
          </div>
      </main>

          <footer id="footer" class="grid-container">
        <div class="widgets row gradient-effect">
            <div class="default-sidebar border-effect">
              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="tag_cloud-2" class="widget widget_epcl_posts_thumbs underline-effect">
                  <h4 class="widget-title title white bordered">最新文章</h4>
                  
                  
                  <article class="item post-0 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://blog.shunzi.tech/post/cpp-multi-thread/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display:block;border-radius:50%;background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20210513192958.png');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2021-05-06">2021-05-06</time>
                      <h4 class="title usmall">
                        <a href="https://blog.shunzi.tech/post/cpp-multi-thread/">C++ 多线程</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  <article class="item post-1 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://blog.shunzi.tech/post/c-basic/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display:block;border-radius:50%;background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20210513192631.png');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2021-04-06">2021-04-06</time>
                      <h4 class="title usmall">
                        <a href="https://blog.shunzi.tech/post/c-basic/">C 基础</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  <article class="item post-2 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://blog.shunzi.tech/post/basic-of-concurrency-one/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display:block;border-radius:50%;background-image: url('https://raw.githubusercontent.com/zjs1224522500/PicGoImages/master//img/blog/20200717213648.png');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2021-04-05">2021-04-05</time>
                      <h4 class="title usmall">
                        <a href="https://blog.shunzi.tech/post/basic-of-concurrency-one/">Series Three of Basic of Concurrency - Condition Variables</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  <div class="clear"></div>
                </section>
              </div>

              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="tag_cloud-2" class="widget widget_tag_cloud underline-effect">
                  <h4 class="widget-title title white bordered">标签云</h4>
                  <div class="tagcloud">
                    
                      <a href="https://blog.shunzi.tech/tag/n2w6bz87h/" class="ctag ctag-0 ctag-n2w6bz87h" aria-label="">编程语言</a>
                    
                      <a href="https://blog.shunzi.tech/tag/3zCwFWPHxH/" class="ctag ctag-1 ctag-3zCwFWPHxH" aria-label="">存储</a>
                    
                      <a href="https://blog.shunzi.tech/tag/la-n8a0mo/" class="ctag ctag-2 ctag-la-n8a0mo" aria-label="">读书笔记</a>
                    
                      <a href="https://blog.shunzi.tech/tag/os/" class="ctag ctag-3 ctag-os" aria-label="">OS</a>
                    
                      <a href="https://blog.shunzi.tech/tag/5uQUdLlSC/" class="ctag ctag-4 ctag-5uQUdLlSC" aria-label="">Paper</a>
                    
                      <a href="https://blog.shunzi.tech/tag/_jfuTNqah/" class="ctag ctag-5 ctag-_jfuTNqah" aria-label="">LSM</a>
                    
                      <a href="https://blog.shunzi.tech/tag/hbaTDSglx-/" class="ctag ctag-6 ctag-hbaTDSglx-" aria-label="">工具</a>
                    
                      <a href="https://blog.shunzi.tech/tag/EO3XpMf_y/" class="ctag ctag-7 ctag-EO3XpMf_y" aria-label="">Linux</a>
                    
                      <a href="https://blog.shunzi.tech/tag/wAFV_pvXZ/" class="ctag ctag-8 ctag-wAFV_pvXZ" aria-label="">cs-course</a>
                    
                      <a href="https://blog.shunzi.tech/tag/VqiGqmxbod/" class="ctag ctag-9 ctag-VqiGqmxbod" aria-label="">6.824</a>
                    
                      <a href="https://blog.shunzi.tech/tag/geK0jEW-T/" class="ctag ctag-10 ctag-geK0jEW-T" aria-label="">分布式</a>
                    
                      <a href="https://blog.shunzi.tech/tag/l8sKsLUAi/" class="ctag ctag-11 ctag-l8sKsLUAi" aria-label="">KVS</a>
                    
                      <a href="https://blog.shunzi.tech/tag/9msH-lUaA/" class="ctag ctag-12 ctag-9msH-lUaA" aria-label="">缓存</a>
                    
                      <a href="https://blog.shunzi.tech/tag/i2b42Y2j6/" class="ctag ctag-13 ctag-i2b42Y2j6" aria-label="">Ceph</a>
                    
                      <a href="https://blog.shunzi.tech/tag/oBVOD8v4ou/" class="ctag ctag-14 ctag-oBVOD8v4ou" aria-label="">一致性</a>
                    
                      <a href="https://blog.shunzi.tech/tag/gqgftpk_y/" class="ctag ctag-15 ctag-gqgftpk_y" aria-label="">AI</a>
                    
                      <a href="https://blog.shunzi.tech/tag/shu-ju-ku/" class="ctag ctag-16 ctag-shu-ju-ku" aria-label="">数据库</a>
                    
                      <a href="https://blog.shunzi.tech/tag/ZnIN9Ge-w/" class="ctag ctag-17 ctag-ZnIN9Ge-w" aria-label="">对象存储</a>
                    
                      <a href="https://blog.shunzi.tech/tag/4zx4ysLGro/" class="ctag ctag-18 ctag-4zx4ysLGro" aria-label="">云计算</a>
                    
                      <a href="https://blog.shunzi.tech/tag/Y_nsOD1At/" class="ctag ctag-19 ctag-Y_nsOD1At" aria-label="">SSD</a>
                    
                      <a href="https://blog.shunzi.tech/tag/E2d1yYZcV8/" class="ctag ctag-20 ctag-E2d1yYZcV8" aria-label="">虚拟化</a>
                    
                      <a href="https://blog.shunzi.tech/tag/PhD/" class="ctag ctag-21 ctag-PhD" aria-label="">Ph.D</a>
                    
                      <a href="https://blog.shunzi.tech/tag/ZqEqvRTvl/" class="ctag ctag-22 ctag-ZqEqvRTvl" aria-label="">网络</a>
                    
                      <a href="https://blog.shunzi.tech/tag/PuY19cs53/" class="ctag ctag-23 ctag-PuY19cs53" aria-label="">仿真</a>
                    
                      <a href="https://blog.shunzi.tech/tag/rIIc9E-ZvN/" class="ctag ctag-24 ctag-rIIc9E-ZvN" aria-label="">系统结构</a>
                    
                      <a href="https://blog.shunzi.tech/tag/fu-wu-qi/" class="ctag ctag-25 ctag-fu-wu-qi" aria-label="">服务器</a>
                    
                      <a href="https://blog.shunzi.tech/tag/X-lnqf1Ex/" class="ctag ctag-26 ctag-X-lnqf1Ex" aria-label="">容器</a>
                    
                      <a href="https://blog.shunzi.tech/tag/5h7k39FKw/" class="ctag ctag-27 ctag-5h7k39FKw" aria-label="">C语言</a>
                    
                      <a href="https://blog.shunzi.tech/tag/diary/" class="ctag ctag-28 ctag-diary" aria-label="">Diary</a>
                    
                      <a href="https://blog.shunzi.tech/tag/DyzFtOe6x/" class="ctag ctag-29 ctag-DyzFtOe6x" aria-label="">计算机基础</a>
                    
                      <a href="https://blog.shunzi.tech/tag/oqE3oKihb/" class="ctag ctag-30 ctag-oqE3oKihb" aria-label="">OpenStack</a>
                    
                      <a href="https://blog.shunzi.tech/tag/p_z7gKe6R/" class="ctag ctag-31 ctag-p_z7gKe6R" aria-label="">中间件</a>
                    
                      <a href="https://blog.shunzi.tech/tag/Test/" class="ctag ctag-32 ctag-Test" aria-label="">测试</a>
                    
                      <a href="https://blog.shunzi.tech/tag/Product-Standard/" class="ctag ctag-33 ctag-Product-Standard" aria-label="">Product Standard</a>
                    
                      <a href="https://blog.shunzi.tech/tag/spring/" class="ctag ctag-34 ctag-spring" aria-label="">Spring</a>
                    
                      <a href="https://blog.shunzi.tech/tag/she-ji-mo-shi/" class="ctag ctag-35 ctag-she-ji-mo-shi" aria-label="">设计模式</a>
                    
                      <a href="https://blog.shunzi.tech/tag/mian-jing/" class="ctag ctag-36 ctag-mian-jing" aria-label="">面经</a>
                    
                      <a href="https://blog.shunzi.tech/tag/suan-fa/" class="ctag ctag-37 ctag-suan-fa" aria-label="">算法</a>
                    
                      <a href="https://blog.shunzi.tech/tag/redis/" class="ctag ctag-38 ctag-redis" aria-label="">Redis</a>
                    
                      <a href="https://blog.shunzi.tech/tag/javaweb/" class="ctag ctag-39 ctag-javaweb" aria-label="">JavaWeb</a>
                    
                      <a href="https://blog.shunzi.tech/tag/KyMCZj2Wl/" class="ctag ctag-40 ctag-KyMCZj2Wl" aria-label="">WEB容器</a>
                    
                      <a href="https://blog.shunzi.tech/tag/javase/" class="ctag ctag-41 ctag-javase" aria-label="">JavaSE</a>
                    
                  </div>
                  <div class="clear"></div>
                </section>
              </div>

              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="epcl_about-2" class="widget widget_epcl_about underline-effect">
                  <h4 class="widget-title title white bordered">关于我</h4>
                  <div class="avatar">
                    <a href="" class="translate-effect thumb"><span class="fullimage cover" style="background-image: url(https://blog.shunzi.tech/images/avatar.png);"></span></a>
                  </div>
                  <div class="info">
                    <h4 class="title small author-name gradient-effect no-margin"><a href="">Elvis Zhang</a></h4>
                    <p class="founder">The easy way or the right way.</p>
                    <div class="social">
                      
                          
                            <a href="https://github.com/zjs1224522500" class="translate-effect" target="_blank"><i class="fa fa-github"></i></a>
                        
                      
                          
                            <a href="https://twitter.com/1224522500Elvis" class="translate-effect" target="_blank"><i class="fa fa-twitter"></i></a>
                        
                      
                        
                      
                        
                      
                        
                      
                    </div> 
                  </div>
                  <div class="clear"></div>
                  </section>
              </div>

            </div>
            <div class="clear"></div>
        </div>

        <div class="logo">
          <a href="https://blog.shunzi.tech"><img src="\media\images\custom-footerLogo.jpg" alt=""></a>
        </div>
        <p class="published border-effect">
          ©2019 共 115 篇文章
          <br/>
          Theme <a href="https://gridea.dev/" target="_blank">「breek」</a> Powered by <a href="https://gridea.dev/" target="_blank">「Gridea」</a>
        </p>
        
        <a href="javascript:void(0)" id="back-to-top" class="epcl-button dark" style="display:none">
          <i class="fa fa-arrow"></i>
        </a>
    </footer>
    
    <div class="clear"></div>

        
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/leancloud-storage/dist/av-min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/valine/1.3.10/Valine.Pure.min.js"></script>
<script>
    new Valine({
        el: '#comments',
        appId: 'Pj5H1z0w7hJlLGJpGBh9NrCq-MdYXbMMI' ,
        appKey: 'LdR8vK5EaBfK87esF7tlbsXe',
        pageSize: 30,
        placeholder: '既然来了，那就留个痕迹吧~',
        visitor: true // 阅读量统计
    })
</script>
    

      
    <script src="https://blog.shunzi.tech/media/js/functions-post.js"></script>

    </div>
    <!-- end: #wrapper -->
  </body>
</html>
